import {
	leverDeal,
	get_country,
	get_config
} from '@/api/index.js'

const state = {
	muit: [],
	ratio: [],
	share: [],
	language: uni.getStorageSync('select') || "zh-CN",
	version: '',
	smsSwitc: true,
	is_open_system: true, //系统开关
	is_open_leagl: true, //周期开关
	is_open_lever: true, //点位开关
	wallet_min_cz: 0, //充值限制最低金额
	wallet_max_cz: 0, //充值限制最高金额
	wallet_min_tx: 0, //提币限制最低金额
	wallet_max_tx: 0, //提币限制最高金额
	cb_remarks: '', //充币说明
	tx_remarks: '', //提币说明
	wallet_tx_num: 0, //当日提现次数
	is_open_systemremarks: '', //系统关闭说明
	is_open_cbiremarks: '', //充币关闭说明
	is_open_tbiremarks: '', //提币关闭说明
	is_open_leaglremarks: '', //周期关闭说明
	is_open_leverremarks: '', //点位关闭说明
	is_open_tbi: true, //提币开关
	is_open_cbi: true, //充币开关,
	is_open_realcbi: true, //初级认证充币开关,
	is_open_realtbi: true, //初级认证提币开关,
	is_open_realhz: true, //初级认证划转开关,
	is_open_realdh: true, //初级认证兑换开关,
	is_open_realzq: true, //初级认证周期开关,
	is_open_realdw: true, //初级认证点位开关,
	is_open_grealcbi: true, //高级认证充币开关,
	is_open_grealtbi: true, //高级认证提币开关,
	is_open_grealhz: true, //高级认证划转开关,
	is_open_grealdh: true, //高级认证兑换开关,
	is_open_grealzq: true, //高级认证周期开关,
	is_open_grealdw: true, //高级认证点位开关,
	countryList: [], //国家列表
	regionCode: [], //电话编码
}

const mutations = {
	SET_MUIT: (state, muit) => {
		state.muit = muit
	},
	SET_RATIO: (state, ratio) => {
		state.ratio = ratio
	},
	SET_SHARE: (state, share) => {
		state.share = share
	},
	SET_LANGUAGE: (state, language) => {
		state.language = language
	},
	SET_VERSION: (state, version) => {
		state.version = version
	},
	SET_SMSSWITC: (state, smsSwitc) => {
		state.smsSwitc = smsSwitc
	},
	SET_IS_OPEN_LEAGL: (state, is_open_leagl) => {
		state.is_open_leagl = is_open_leagl
	},
	SET_IS_OPEN_LEVER: (state, is_open_lever) => {
		state.is_open_lever = is_open_lever
	},
	SET_WALLET_MIN_CZ: (state, wallet_min_cz) => {
		state.wallet_min_cz = wallet_min_cz
	},
	SET_WALLET_MAX_CZ: (state, wallet_max_cz) => {
		state.wallet_max_cz = wallet_max_cz
	},
	SET_WALLET_MIN_TX: (state, wallet_min_tx) => {
		state.wallet_min_tx = wallet_min_tx
	},
	SET_WALLET_MAX_TX: (state, wallet_max_tx) => {
		state.wallet_max_tx = wallet_max_tx
	},
	SET_CB_REMARKS: (state, cb_remarks) => {
		state.cb_remarks = cb_remarks
	},
	SET_TX_REMARKS: (state, tx_remarks) => {
		state.tx_remarks = tx_remarks
	},
	SET_WALLET_TX_NUM: (state, wallet_tx_num) => {
		state.wallet_tx_num = wallet_tx_num
	},
	SET_IS_OPEN_SYSTEMREMARKS: (state, is_open_systemremarks) => {
		state.is_open_systemremarks = is_open_systemremarks
	},
	SET_IS_OPEN_SYSTEM: (state, is_open_system) => {
		state.is_open_system = is_open_system
	},
	SET_IS_OPEN_CBIREMARKS: (state, is_open_cbiremarks) => {
		state.is_open_cbiremarks = is_open_cbiremarks
	},
	SET_IS_OPEN_TBIREMARKS: (state, is_open_tbiremarks) => {
		state.is_open_tbiremarks = is_open_tbiremarks
	},
	SET_IS_OPEN_LEAGLREMARKS: (state, is_open_leaglremarks) => {
		state.is_open_leaglremarks = is_open_leaglremarks
	},
	SET_IS_OPEN_LEVERREMARKS: (state, is_open_leverremarks) => {
		state.is_open_leverremarks = is_open_leverremarks
	},
	SET_IS_OPEN_TBI: (state, is_open_tbi) => {
		state.is_open_tbi = is_open_tbi
	},
	SET_IS_OPEN_CBI: (state, is_open_cbi) => {
		state.is_open_cbi = is_open_cbi
	},
	SET_IS_OPEN_REALCBI: (state, is_open_realcbi) => {
		state.is_open_realcbi = is_open_realcbi
	},
	SET_IS_OPEN_REALTBI: (state, is_open_realtbi) => {
		state.is_open_realtbi = is_open_realtbi
	},
	SET_IS_OPEN_REALHZ: (state, is_open_realhz) => {
		state.is_open_realhz = is_open_realhz
	},
	SET_IS_OPEN_REALDH: (state, is_open_realdh) => {
		state.is_open_realdh = is_open_realdh
	},
	SET_IS_OPEN_REALZQ: (state, is_open_realzq) => {
		state.is_open_realzq = is_open_realzq
	},
	SET_IS_OPEN_REALDW: (state, is_open_realdw) => {
		state.is_open_realdw = is_open_realdw
	},
	SET_IS_OPEN_GREALCBI: (state, is_open_grealcbi) => {
		state.is_open_grealcbi = is_open_grealcbi
	},
	SET_IS_OPEN_GREALTBI: (state, is_open_grealtbi) => {
		state.is_open_grealtbi = is_open_grealtbi
	},
	SET_IS_OPEN_GREALHZ: (state, is_open_grealhz) => {
		state.is_open_grealhz = is_open_grealhz
	},
	SET_IS_OPEN_GREALDH: (state, is_open_grealdh) => {
		state.is_open_grealdh = is_open_grealdh
	},
	SET_IS_OPEN_GREALZQ: (state, is_open_grealzq) => {
		state.is_open_grealzq = is_open_grealzq
	},
	SET_IS_OPEN_GREALDW: (state, is_open_grealdw) => {
		state.is_open_grealdw = is_open_grealdw
	},
	SET_COUNTRY_LIST: (state, countryList) => {
		state.countryList = countryList
	},
	SET_REGION_CODE: (state, regionCode) => {
		state.regionCode = regionCode
	},
}

const actions = {
	// get wallet list
	getLeverDeal({
		commit
	}) {
		return new Promise((resolve, reject) => {
			leverDeal({legal_id: 1, currency_id: 11}).then(response => {
				if (response.error) return reject();
				let data = response.res;
				// console.log(data.multiple)
				commit('SET_MUIT', data.multiple.muit)
				commit('SET_RATIO', data.multiple.ratio)
				commit('SET_SHARE', data.multiple.share)
				// for (let i in data) {
				// 	let obj = {
				// 		title: data[i].name,
				// 		id: data[i].id,
				// 		rate: data[i].rate
				// 	}
				// 	arry.push(obj)
				// }
				// commit('SET_CURRENCYLIST', arry || [])
				resolve()
			})
		})
	},
	getConfig({commit}) {
		return new Promise((resolve, reject) => {
			get_config().then(res => {
				if (res.error) return reject();
				let data = res.res;
				for (let i in data) {
					if (data[i].id === 20) {
						commit('SET_SMSSWITC', data[i].value === '1'?true: false);
					}
					if (data[i].id === 1) {
						commit('SET_VERSION', data[i].value);
					}
					if (data[i].key === "is_open_leagl") {
						commit('SET_IS_OPEN_LEAGL', data[i].value === '1'?true: false);
					}
					if (data[i].key === "is_open_tbi") {
						commit('SET_IS_OPEN_TBI', data[i].value === '1'?true: false);
					}
					if (data[i].key === "is_open_cbi") {
						commit('SET_IS_OPEN_CBI', data[i].value === '1'?true: false);
					}
					if (data[i].key === "is_open_system") {
						commit('SET_IS_OPEN_SYSTEM', data[i].value === '1'?true: false);
					}
					if (data[i].key === "is_open_lever") {
						commit('SET_IS_OPEN_LEVER', data[i].value === '1'?true: false);
					}
					if (data[i].key === "is_open_realcbi") {
						commit('SET_IS_OPEN_REALCBI', data[i].value === '1'?true: false);
					}
					if (data[i].key === "is_open_realtbi") {
						commit('SET_IS_OPEN_REALTBI', data[i].value === '1'?true: false);
					}
					if (data[i].key === "is_open_realhz") {
						commit('SET_IS_OPEN_REALHZ', data[i].value === '1'?true: false);
					}
					if (data[i].key === "is_open_realdh") {
						commit('SET_IS_OPEN_REALDH', data[i].value === '1'?true: false);
					}
					if (data[i].key === "is_open_realzq") {
						commit('SET_IS_OPEN_REALZQ', data[i].value === '1'?true: false);
					}
					if (data[i].key === "is_open_realdw") {
						commit('SET_IS_OPEN_REALDW', data[i].value === '1'?true: false);
					}
					if (data[i].key === "is_open_grealcbi") {
						commit('SET_IS_OPEN_GREALCBI', data[i].value === '1'?true: false);
					}
					if (data[i].key === "is_open_grealtbi") {
						commit('SET_IS_OPEN_GREALTBI', data[i].value === '1'?true: false);
					}
					if (data[i].key === "is_open_grealhz") {
						commit('SET_IS_OPEN_GREALHZ', data[i].value === '1'?true: false);
					}
					if (data[i].key === "is_open_grealdh") {
						commit('SET_IS_OPEN_GREALDH', data[i].value === '1'?true: false);
					}
					if (data[i].key === "is_open_grealzq") {
						commit('SET_IS_OPEN_GREALZQ', data[i].value === '1'?true: false);
					}
					if (data[i].key === "is_open_grealdw") {
						commit('SET_IS_OPEN_GREALDW', data[i].value === '1'?true: false);
					}
					if (data[i].key === "wallet_min_cz") {
						commit('SET_WALLET_MIN_CZ', Number(data[i].value));
					}
					if (data[i].key === "wallet_max_cz") {
						commit('SET_WALLET_MAX_CZ', Number(data[i].value));
					}
					if (data[i].key === "wallet_min_tx") {
						commit('SET_WALLET_MIN_TX', Number(data[i].value));
					}
					if (data[i].key === "wallet_min_tx") {
						commit('SET_WALLET_MIN_TX', Number(data[i].value));
					}
					if (data[i].key === "wallet_max_tx") {
						commit('SET_WALLET_MAX_TX', Number(data[i].value));
					}
					if (data[i].key === "cb_remarks") {
						commit('SET_CB_REMARKS', data[i].value);
					}
					if (data[i].key === "tx_remarks") {
						commit('SET_TX_REMARKS', data[i].value);
					}
					if (data[i].key === "wallet_tx_num") {
						commit('SET_WALLET_TX_NUM', Number(data[i].value));
					}
					if (data[i].key === "is_open_systemremarks") {
						commit('SET_IS_OPEN_SYSTEMREMARKS', data[i].value);
					}
					if (data[i].key === "is_open_cbiremarks") {
						commit('SET_IS_OPEN_CBIREMARKS', data[i].value);
					}
					if (data[i].key === "is_open_tbiremarks") {
						commit('SET_IS_OPEN_TBIREMARKS', data[i].value);
					}
					if (data[i].key === "is_open_leaglremarks") {
						commit('SET_IS_OPEN_LEAGLREMARKS', data[i].value);
					}
					if (data[i].key === "is_open_leverremarks") {
						commit('SET_IS_OPEN_LEVERREMARKS', data[i].value);
					}
				}
				resolve();
			})
		})
	},
	async getCountry({commit}) {
		let {error, res} = await get_country();
		if (error) return;
		let arry = [], code = [];
		for (let i in res) {
			let obj = {
				id: res[i].id,
				title: res[i].cnname,
				code: res[i].code
			}
			let codeObj = {
				value: res[i].code
			}
			arry.push(obj)
			code.push(codeObj)
		}
		commit('SET_COUNTRY_LIST', arry);
		commit('SET_REGION_CODE', code);
	}
}

export default {
	namespaced: true,
	state,
	mutations,
	actions
}
